/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * File: LBG_Arctan_FOC.c
 *
 * Code generated for Simulink model 'LBG_Arctan_FOC'.
 *
 * Model version                  : 2.42
 * Simulink Coder version         : 9.8 (R2022b) 13-May-2022
 * C/C++ source code generated on : Thu Feb 20 14:11:54 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Intel->x86-64 (Windows64)
 * Code generation objectives: Unspecified
 * Validation result: Not run
 */

#include "LBG_Arctan_FOC.h"
#include "rtwtypes.h"
#include "LBG_Arctan_FOC_private.h"
#include <math.h>
#include "rt_nonfinite.h"
#include "rt_modf_snf.h"
#include "rt_atan2f_snf.h"

/* Named constants for Chart: '<S2>/Chart' */
#define LBG_Arctan_FOC_IN_CLL          ((uint8_T)1U)
#define LBG_Arctan_FOC_IN_CLL1         ((uint8_T)2U)
#define LBG_Arctan_FOC_IN_Init         ((uint8_T)3U)
#define LBG_Arctan_FOC_IN_OPL          ((uint8_T)4U)
#define LBG_Arctan_FOC_IN_OPL1         ((uint8_T)5U)

int_T LBG_Arctan_FOC_GlobalTID[3];
const rtTimingBridge *LBG_Arctan_FOC_TimingBrdg;

/* Exported block signals */
real32_T LGB_theta;                    /* '<S31>/Math Function' */
real32_T LGB_SPD;                      /* '<S44>/Add1' */
real32_T OB_LGB_SPD;                   /* '<S47>/Add1' */
MdlrefDW_LBG_Arctan_FOC_T LBG_Arctan_FOC_MdlrefDW;

/* Block signals (default storage) */
B_LBG_Arctan_FOC_c_T LBG_Arctan_FOC_B;

/* Block states (default storage) */
DW_LBG_Arctan_FOC_f_T LBG_Arctan_FOC_DW;

/*
 * Output and update for enable system:
 *    '<S17>/per Uint'
 *    '<S41>/per Uint'
 */
void LBG_Arctan_FOC_perUint(boolean_T rtu_Enable, real32_T rtu_In1, real32_T
  *rty_Out1)
{
  /* Outputs for Enabled SubSystem: '<S17>/per Uint' incorporates:
   *  EnablePort: '<S29>/Enable'
   */
  if (rtu_Enable) {
    real32_T rtb_Gain_b;

    /* Gain: '<S29>/Gain' */
    rtb_Gain_b = 0.159154937F * rtu_In1;

    /* Switch: '<S29>/Switch' incorporates:
     *  Bias: '<S29>/Bias'
     */
    if (rtb_Gain_b >= 0.0F) {
      *rty_Out1 = rtb_Gain_b;
    } else {
      *rty_Out1 = rtb_Gain_b + 1.0F;
    }

    /* End of Switch: '<S29>/Switch' */
  }

  /* End of Outputs for SubSystem: '<S17>/per Uint' */
}

/* System initialize for referenced model: 'LBG_Arctan_FOC' */
void LBG_Arctan_FOC_Init(void)
{
  /* SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator3' incorporates:
   *  SubSystem: '<S1>/Speed_Control'
   */
  /* SystemInitialize for Enabled SubSystem: '<S4>/Subsystem' */
  /* SystemInitialize for SignalConversion generated from: '<S334>/Id_Ref' */
  LBG_Arctan_FOC_B.OutportBufferForId_Ref = LBG_Arctan_FOC_ConstB.Constant;

  /* End of SystemInitialize for SubSystem: '<S4>/Subsystem' */
  /* End of SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator3' */
  /* Start for SwitchCase: '<S9>/Switch Case' */
  LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;

  /* End of SystemInitialize for S-Function (fcgen): '<S1>/Function-Call Generator4' */
}

/* Enable for referenced model: 'LBG_Arctan_FOC' */
void LBG_Arctan_FOC_Enable(void)
{
  /* Enable for S-Function (fcgen): '<S1>/Function-Call Generator5' incorporates:
   *  SubSystem: '<S1>/10ms_Task'
   */
  /* Enable for Chart: '<S2>/Chart' */
  LBG_Arctan_FOC_DW.presentTicks = rtmGetClockTick2();
  LBG_Arctan_FOC_DW.previousTicks = LBG_Arctan_FOC_DW.presentTicks;

  /* End of Enable for S-Function (fcgen): '<S1>/Function-Call Generator5' */

  /* Enable for S-Function (fcgen): '<S1>/Function-Call Generator4' incorporates:
   *  SubSystem: '<S1>/FOC'
   */
  LBG_Arctan_FOC_DW.FOC_RESET_ELAPS_T = true;

  /* Enable for DiscreteIntegrator: '<S249>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE = 1U;

  /* Enable for DiscreteIntegrator: '<S297>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_e = 1U;

  /* Enable for DiscreteIntegrator: '<S82>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_d = 1U;

  /* Enable for DiscreteIntegrator: '<S153>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_g = 1U;

  /* Enable for DiscreteIntegrator: '<S201>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m = 1U;

  /* End of Enable for S-Function (fcgen): '<S1>/Function-Call Generator4' */
}

/* Disable for referenced model: 'LBG_Arctan_FOC' */
void LBG_Arctan_FOC_Disable(void)
{
  /* Disable for S-Function (fcgen): '<S1>/Function-Call Generator5' incorporates:
   *  SubSystem: '<S1>/10ms_Task'
   */
  /* Disable for Chart: '<S2>/Chart' */
  LBG_Arctan_FOC_DW.presentTicks = rtmGetClockTick2();
  LBG_Arctan_FOC_DW.elapsedTicks = LBG_Arctan_FOC_DW.presentTicks -
    LBG_Arctan_FOC_DW.previousTicks;
  LBG_Arctan_FOC_DW.previousTicks = LBG_Arctan_FOC_DW.presentTicks;
  if (LBG_Arctan_FOC_DW.temporalCounter_i1 + LBG_Arctan_FOC_DW.elapsedTicks <=
      63U) {
    LBG_Arctan_FOC_DW.temporalCounter_i1 = (uint8_T)
      (LBG_Arctan_FOC_DW.temporalCounter_i1 + LBG_Arctan_FOC_DW.elapsedTicks);
  } else {
    LBG_Arctan_FOC_DW.temporalCounter_i1 = 63U;
  }

  /* End of Disable for Chart: '<S2>/Chart' */
  /* End of Disable for S-Function (fcgen): '<S1>/Function-Call Generator5' */

  /* Disable for S-Function (fcgen): '<S1>/Function-Call Generator3' incorporates:
   *  SubSystem: '<S1>/Speed_Control'
   */
  /* Disable for Enabled SubSystem: '<S4>/Subsystem' */
  LBG_Arctan_FOC_DW.Subsystem_MODE = false;

  /* End of Disable for SubSystem: '<S4>/Subsystem' */
  /* End of Disable for S-Function (fcgen): '<S1>/Function-Call Generator3' */

  /* Disable for S-Function (fcgen): '<S1>/Function-Call Generator4' incorporates:
   *  SubSystem: '<S1>/FOC'
   */
  /* Disable for SwitchCase: '<S9>/Switch Case' */
  LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;

  /* End of Disable for S-Function (fcgen): '<S1>/Function-Call Generator4' */
}

/* Output and update for referenced model: 'LBG_Arctan_FOC' */
void LBG_Arctan_FOC_step(real32_T arg_Target_Speed, real32_T arg_Iabc[3],
  real32_T arg_Real_Theta, real32_T arg_Vabc_PU[3])
{
  real_T tmp;
  int32_T sector;
  real32_T T1;
  real32_T T2;
  real32_T beta;
  real32_T rtb_Saturation;
  real32_T rtb_Saturation_a;
  real32_T rtb_Saturation_h;
  real32_T rtb_Saturation_l;
  real32_T rtb_Sum2;
  real32_T rtb_Sum3;
  real32_T rtb_Sum6;
  real32_T rtb_Sum_b;
  real32_T rtb_Sum_f;
  real32_T rtb_Tcmp3;
  real32_T rtb_Vbeta;
  real32_T rtb_algDD_o1_m;
  real32_T rtb_ibeta;
  real32_T ta;
  uint16_T rtb_Get_Integer;
  int8_T rtPrevAction;
  int8_T tmp_0;

  /* DataStoreWrite: '<S1>/Data Store Write' */
  LBG_Arctan_FOC_DW.Real_Theta = arg_Real_Theta;
  if (rtmIsSampleHit(2, 0)) {
    /* S-Function (fcgen): '<S1>/Function-Call Generator5' incorporates:
     *  SubSystem: '<S1>/10ms_Task'
     */
    /* Chart: '<S2>/Chart' incorporates:
     *  Delay: '<S1>/Delay'
     */
    LBG_Arctan_FOC_DW.presentTicks = rtmGetClockTick2();
    LBG_Arctan_FOC_DW.elapsedTicks = LBG_Arctan_FOC_DW.presentTicks -
      LBG_Arctan_FOC_DW.previousTicks;
    LBG_Arctan_FOC_DW.previousTicks = LBG_Arctan_FOC_DW.presentTicks;
    if (LBG_Arctan_FOC_DW.temporalCounter_i1 + LBG_Arctan_FOC_DW.elapsedTicks <=
        63U) {
      LBG_Arctan_FOC_DW.temporalCounter_i1 = (uint8_T)
        (LBG_Arctan_FOC_DW.temporalCounter_i1 + LBG_Arctan_FOC_DW.elapsedTicks);
    } else {
      LBG_Arctan_FOC_DW.temporalCounter_i1 = 63U;
    }

    if (LBG_Arctan_FOC_DW.is_active_c1_LBG_Arctan_FOC == 0U) {
      LBG_Arctan_FOC_DW.is_active_c1_LBG_Arctan_FOC = 1U;
      LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_Init;
      LBG_Arctan_FOC_DW.temporalCounter_i1 = 0U;
      LBG_Arctan_FOC_B.Motor_State = 0.0;
    } else {
      switch (LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC) {
       case LBG_Arctan_FOC_IN_CLL:
        if (arg_Target_Speed < 0.0F) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_Init;
          LBG_Arctan_FOC_DW.temporalCounter_i1 = 0U;
          LBG_Arctan_FOC_B.Motor_State = 0.0;
        } else {
          LBG_Arctan_FOC_B.Motor_State = 2.0;
          LBG_Arctan_FOC_DW.time = 0.0;
        }
        break;

       case LBG_Arctan_FOC_IN_CLL1:
        if (arg_Target_Speed > 0.0F) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_Init;
          LBG_Arctan_FOC_DW.temporalCounter_i1 = 0U;
          LBG_Arctan_FOC_B.Motor_State = 0.0;
        } else {
          LBG_Arctan_FOC_B.Motor_State = 2.0;
          LBG_Arctan_FOC_DW.time = 0.0;
        }
        break;

       case LBG_Arctan_FOC_IN_Init:
        if ((LBG_Arctan_FOC_DW.temporalCounter_i1 >= 50U) && (arg_Target_Speed >=
             0.0F)) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_OPL;
          LBG_Arctan_FOC_B.Motor_State = 1.0;
          LBG_Arctan_FOC_DW.time++;
        } else if ((LBG_Arctan_FOC_DW.temporalCounter_i1 >= 50U) &&
                   (arg_Target_Speed < 0.0F)) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_OPL1;
          LBG_Arctan_FOC_B.Motor_State = 3.0;
          LBG_Arctan_FOC_DW.time++;
        } else {
          LBG_Arctan_FOC_B.Motor_State = 0.0;
        }
        break;

       case LBG_Arctan_FOC_IN_OPL:
        if ((LBG_Arctan_FOC_DW.time > 100.0) && (LGB_SPD > 900.0F)) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_CLL;
          LBG_Arctan_FOC_B.Motor_State = 2.0;
          LBG_Arctan_FOC_DW.time = 0.0;
        } else {
          LBG_Arctan_FOC_B.Motor_State = 1.0;
          LBG_Arctan_FOC_DW.time++;
        }
        break;

       default:
        /* case IN_OPL1: */
        if ((LBG_Arctan_FOC_DW.time > 100.0) && (LGB_SPD < -900.0F)) {
          LBG_Arctan_FOC_DW.is_c1_LBG_Arctan_FOC = LBG_Arctan_FOC_IN_CLL1;
          LBG_Arctan_FOC_B.Motor_State = 2.0;
          LBG_Arctan_FOC_DW.time = 0.0;
        } else {
          LBG_Arctan_FOC_B.Motor_State = 3.0;
          LBG_Arctan_FOC_DW.time++;
        }
        break;
      }
    }

    /* End of Chart: '<S2>/Chart' */
    /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator5' */
  }

  if (rtmIsSampleHit(1, 0)) {
    /* S-Function (fcgen): '<S1>/Function-Call Generator3' incorporates:
     *  SubSystem: '<S1>/Speed_Control'
     */
    /* Outputs for Enabled SubSystem: '<S4>/Subsystem' incorporates:
     *  EnablePort: '<S334>/Enable'
     */
    /* RelationalOperator: '<S333>/Compare' incorporates:
     *  Constant: '<S333>/Constant'
     */
    if (LBG_Arctan_FOC_B.Motor_State == 2.0) {
      if (!LBG_Arctan_FOC_DW.Subsystem_MODE) {
        LBG_Arctan_FOC_DW.Subsystem_RESET_ELAPS_T = true;

        /* Enable for DiscreteIntegrator: '<S367>/Integrator' */
        LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_h = 1U;
        LBG_Arctan_FOC_DW.Subsystem_MODE = true;
      }

      if (LBG_Arctan_FOC_DW.Subsystem_RESET_ELAPS_T) {
        LBG_Arctan_FOC_DW.Subsystem_ELAPS_T = 0U;
      } else {
        LBG_Arctan_FOC_DW.Subsystem_ELAPS_T = rtmGetClockTick1() -
          LBG_Arctan_FOC_DW.Subsystem_PREV_T;
      }

      LBG_Arctan_FOC_DW.Subsystem_PREV_T = rtmGetClockTick1();
      LBG_Arctan_FOC_DW.Subsystem_RESET_ELAPS_T = false;

      /* SignalConversion generated from: '<S334>/Id_Ref' */
      LBG_Arctan_FOC_B.OutportBufferForId_Ref = LBG_Arctan_FOC_ConstB.Constant;

      /* Sum: '<S334>/Sum' incorporates:
       *  Delay: '<S1>/Delay'
       */
      rtb_Sum_b = arg_Target_Speed - LGB_SPD;

      /* DiscreteIntegrator: '<S367>/Integrator' */
      if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_h == 0) {
        /* DiscreteIntegrator: '<S367>/Integrator' */
        LBG_Arctan_FOC_DW.Integrator_DSTATE_cq += 0.001F * (real32_T)
          LBG_Arctan_FOC_DW.Subsystem_ELAPS_T
          * LBG_Arctan_FOC_DW.Integrator_PREV_U_a;
      }

      /* End of DiscreteIntegrator: '<S367>/Integrator' */

      /* Sum: '<S376>/Sum' incorporates:
       *  Gain: '<S372>/Proportional Gain'
       */
      LBG_Arctan_FOC_B.Saturation = 0.000132054571F * rtb_Sum_b +
        LBG_Arctan_FOC_DW.Integrator_DSTATE_cq;

      /* Saturate: '<S374>/Saturation' */
      if (LBG_Arctan_FOC_B.Saturation > 3.26732683F) {
        /* Sum: '<S376>/Sum' incorporates:
         *  Saturate: '<S374>/Saturation'
         */
        LBG_Arctan_FOC_B.Saturation = 3.26732683F;
      } else if (LBG_Arctan_FOC_B.Saturation < -3.26732683F) {
        /* Sum: '<S376>/Sum' incorporates:
         *  Saturate: '<S374>/Saturation'
         */
        LBG_Arctan_FOC_B.Saturation = -3.26732683F;
      }

      /* End of Saturate: '<S374>/Saturation' */

      /* Update for DiscreteIntegrator: '<S367>/Integrator' incorporates:
       *  Gain: '<S364>/Integral Gain'
       */
      LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_h = 0U;
      LBG_Arctan_FOC_DW.Integrator_PREV_U_a = 0.00208796607F * rtb_Sum_b;
    } else {
      LBG_Arctan_FOC_DW.Subsystem_MODE = false;
    }

    /* End of RelationalOperator: '<S333>/Compare' */
    /* End of Outputs for SubSystem: '<S4>/Subsystem' */
    /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator3' */
  }

  /* S-Function (fcgen): '<S1>/Function-Call Generator4' incorporates:
   *  SubSystem: '<S1>/FOC'
   */
  if (LBG_Arctan_FOC_DW.FOC_RESET_ELAPS_T) {
    LBG_Arctan_FOC_DW.FOC_ELAPS_T = 0U;
  } else {
    LBG_Arctan_FOC_DW.FOC_ELAPS_T = rtmGetClockTick0() -
      LBG_Arctan_FOC_DW.FOC_PREV_T;
  }

  /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
   *  ActionPort: '<S332>/Action Port'
   */
  /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S330>/Action Port'
   */
  /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
   *  ActionPort: '<S332>/Action Port'
   */
  /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
   *  ActionPort: '<S330>/Action Port'
   */
  /* SwitchCase: '<S9>/Switch Case' */
  LBG_Arctan_FOC_DW.FOC_PREV_T = rtmGetClockTick0();

  /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem1' */
  /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem3' */
  /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem1' */
  /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem3' */
  LBG_Arctan_FOC_DW.FOC_RESET_ELAPS_T = false;

  /* MATLAB Function: '<S7>/Clark2' */
  rtb_Sum_b = arg_Iabc[0] * 2.0F / 3.0F - (arg_Iabc[1] + arg_Iabc[2]) / 3.0F;
  rtb_ibeta = (arg_Iabc[1] - arg_Iabc[2]) * 1.73205078F / 3.0F;

  /* Saturate: '<S10>/Saturation' incorporates:
   *  Delay: '<S10>/Delay'
   */
  if (LBG_Arctan_FOC_DW.Delay_DSTATE_n > 3000.0F) {
    /* Sum: '<S115>/sum_beta' */
    LBG_Arctan_FOC_DW.Delay_DSTATE_n = 3000.0F;
  } else if (LBG_Arctan_FOC_DW.Delay_DSTATE_n < 10.0F) {
    /* Sum: '<S115>/sum_beta' */
    LBG_Arctan_FOC_DW.Delay_DSTATE_n = 10.0F;
  }

  /* End of Saturate: '<S10>/Saturation' */

  /* SwitchCase: '<S9>/Switch Case' */
  rtPrevAction = LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem;
  LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = -1;
  tmp = trunc(LBG_Arctan_FOC_B.Motor_State);
  if (rtIsNaN(tmp) || rtIsInf(tmp)) {
    tmp = 0.0;
  } else {
    tmp = fmod(tmp, 4.294967296E+9);
  }

  switch (tmp < 0.0 ? -(int32_T)(uint32_T)-tmp : (int32_T)(uint32_T)tmp) {
   case 0:
    LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 0;
    break;

   case 1:
    LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 1;
    break;

   case 2:
    LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 2;
    break;

   case 3:
    LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem = 3;
    break;
  }

  switch (LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem) {
   case 0:
    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem' incorporates:
     *  ActionPort: '<S329>/Action Port'
     */
    /* Merge: '<S9>/Merge' incorporates:
     *  Constant: '<S329>/Constant1'
     *  SignalConversion generated from: '<S329>/Id_Ref'
     */
    LBG_Arctan_FOC_B.Merge = 0.4F;

    /* Merge: '<S9>/Merge1' incorporates:
     *  Constant: '<S329>/Constant'
     *  SignalConversion generated from: '<S329>/Iq_Ref'
     */
    LBG_Arctan_FOC_B.Merge1 = 0.0F;

    /* Merge: '<S9>/Merge2' incorporates:
     *  Constant: '<S329>/Constant2'
     *  SignalConversion generated from: '<S329>/Theta'
     */
    LBG_Arctan_FOC_B.Merge2 = 0.0F;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem' */
    break;

   case 1:
    if (LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem != rtPrevAction) {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = true;

      /* Enable for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
       *  ActionPort: '<S330>/Action Port'
       */
      /* Enable for SwitchCase: '<S9>/Switch Case' incorporates:
       *  DiscreteIntegrator: '<S330>/Discrete-Time Integrator'
       *  DiscreteIntegrator: '<S330>/Discrete-Time Integrator1'
       */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m = 1U;
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n = 1U;

      /* End of Enable for SubSystem: '<S9>/Switch Case Action Subsystem1' */
    }

    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
     *  ActionPort: '<S330>/Action Port'
     */
    if (LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE) {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP = 0U;
    } else {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP =
        LBG_Arctan_FOC_DW.FOC_PREV_T
        - LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV;
    }

    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV =
      LBG_Arctan_FOC_DW.FOC_PREV_T;
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = false;

    /* DiscreteIntegrator: '<S330>/Discrete-Time Integrator1' */
    if (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m == 0) {
      /* DiscreteIntegrator: '<S330>/Discrete-Time Integrator1' */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_l += 5.0E-5F * (real32_T)
        LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP *
        LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__o;
    }

    /* End of DiscreteIntegrator: '<S330>/Discrete-Time Integrator1' */

    /* Math: '<S330>/Math Function' incorporates:
     *  Constant: '<S330>/Constant4'
     *  DataStoreWrite: '<S330>/Data Store Write'
     */
    LBG_Arctan_FOC_DW.OPL_Theta = rt_modf_snf
      (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTAT_l, 6.28318548F);

    /* Merge: '<S9>/Merge' incorporates:
     *  Constant: '<S330>/Constant1'
     *  SignalConversion generated from: '<S330>/Id_Ref'
     */
    LBG_Arctan_FOC_B.Merge = 0.4F;

    /* Merge: '<S9>/Merge1' incorporates:
     *  Constant: '<S330>/Constant'
     *  SignalConversion generated from: '<S330>/Iq_Ref'
     */
    LBG_Arctan_FOC_B.Merge1 = 0.0F;

    /* DiscreteIntegrator: '<S330>/Discrete-Time Integrator' */
    if (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n == 0) {
      /* DiscreteIntegrator: '<S330>/Discrete-Time Integrator' */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_e += 5.0E-5F * (real32_T)
        LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_ELAP *
        LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_b;
    }

    /* End of DiscreteIntegrator: '<S330>/Discrete-Time Integrator' */

    /* Merge: '<S9>/Merge2' incorporates:
     *  DataStoreWrite: '<S330>/Data Store Write'
     *  SignalConversion generated from: '<S330>/Theta'
     */
    LBG_Arctan_FOC_B.Merge2 = LBG_Arctan_FOC_DW.OPL_Theta;

    /* Update for DiscreteIntegrator: '<S330>/Discrete-Time Integrator1' incorporates:
     *  Gain: '<S330>/Gain'
     *  Gain: '<S330>/Gain1'
     */
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTE_m = 0U;
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV__o = 0.116666667F *
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE_e * 6.28318548F;

    /* Update for DiscreteIntegrator: '<S330>/Discrete-Time Integrator' */
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_n = 0U;
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U_b =
      LBG_Arctan_FOC_ConstB.Divide_d;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem1' */
    break;

   case 2:
    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem2' incorporates:
     *  ActionPort: '<S331>/Action Port'
     */
    /* Merge: '<S9>/Merge' incorporates:
     *  SignalConversion generated from: '<S331>/Id'
     */
    LBG_Arctan_FOC_B.Merge = LBG_Arctan_FOC_B.OutportBufferForId_Ref;

    /* Merge: '<S9>/Merge1' incorporates:
     *  SignalConversion generated from: '<S331>/Iq'
     */
    LBG_Arctan_FOC_B.Merge1 = LBG_Arctan_FOC_B.Saturation;

    /* Merge: '<S9>/Merge2' incorporates:
     *  Delay: '<S3>/Delay'
     *  SignalConversion generated from: '<S331>/Obs_Theta'
     */
    LBG_Arctan_FOC_B.Merge2 = LGB_theta;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem2' */
    break;

   case 3:
    if (LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem != rtPrevAction) {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_RESE = true;

      /* Enable for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
       *  ActionPort: '<S332>/Action Port'
       */
      /* Enable for SwitchCase: '<S9>/Switch Case' incorporates:
       *  DiscreteIntegrator: '<S332>/Discrete-Time Integrator'
       *  DiscreteIntegrator: '<S332>/Discrete-Time Integrator1'
       */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ = 1U;
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E = 1U;

      /* End of Enable for SubSystem: '<S9>/Switch Case Action Subsystem3' */
    }

    /* Outputs for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
     *  ActionPort: '<S332>/Action Port'
     */
    if (LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_RESE) {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_ELAP = 0U;
    } else {
      LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_ELAP =
        LBG_Arctan_FOC_DW.FOC_PREV_T
        - LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_PREV;
    }

    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_PREV =
      LBG_Arctan_FOC_DW.FOC_PREV_T;
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_RESE = false;

    /* DiscreteIntegrator: '<S332>/Discrete-Time Integrator1' */
    if (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ == 0) {
      /* DiscreteIntegrator: '<S332>/Discrete-Time Integrator1' */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTATE += 5.0E-5F * (real32_T)
        LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_ELAP *
        LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV_U;
    }

    /* End of DiscreteIntegrator: '<S332>/Discrete-Time Integrator1' */

    /* Math: '<S332>/Math Function' incorporates:
     *  Constant: '<S332>/Constant4'
     *  DataStoreWrite: '<S332>/Data Store Write'
     */
    LBG_Arctan_FOC_DW.OPL_Theta = rt_modf_snf
      (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_DSTATE, 6.28318548F);

    /* Merge: '<S9>/Merge' incorporates:
     *  Constant: '<S332>/Constant1'
     *  SignalConversion generated from: '<S332>/Id_Ref'
     */
    LBG_Arctan_FOC_B.Merge = 0.4F;

    /* Merge: '<S9>/Merge1' incorporates:
     *  Constant: '<S332>/Constant'
     *  SignalConversion generated from: '<S332>/Iq_Ref'
     */
    LBG_Arctan_FOC_B.Merge1 = 0.0F;

    /* DiscreteIntegrator: '<S332>/Discrete-Time Integrator' */
    if (LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E == 0) {
      /* DiscreteIntegrator: '<S332>/Discrete-Time Integrator' */
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE += 5.0E-5F * (real32_T)
        LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_ELAP *
        LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U;
    }

    /* End of DiscreteIntegrator: '<S332>/Discrete-Time Integrator' */

    /* Merge: '<S9>/Merge2' incorporates:
     *  DataStoreWrite: '<S332>/Data Store Write'
     *  SignalConversion generated from: '<S332>/Theta'
     */
    LBG_Arctan_FOC_B.Merge2 = LBG_Arctan_FOC_DW.OPL_Theta;

    /* Update for DiscreteIntegrator: '<S332>/Discrete-Time Integrator1' incorporates:
     *  Gain: '<S332>/Gain'
     *  Gain: '<S332>/Gain1'
     */
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_SYSTEM_ = 0U;
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator1_PREV_U = 0.116666667F *
      LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_DSTATE * 6.28318548F;

    /* Update for DiscreteIntegrator: '<S332>/Discrete-Time Integrator' */
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_SYSTEM_E = 0U;
    LBG_Arctan_FOC_DW.DiscreteTimeIntegrator_PREV_U =
      LBG_Arctan_FOC_ConstB.Divide;

    /* End of Outputs for SubSystem: '<S9>/Switch Case Action Subsystem3' */
    break;
  }

  /* Sum: '<S7>/Sum2' incorporates:
   *  MATLAB Function: '<S7>/Park'
   */
  rtb_Sum2 = LBG_Arctan_FOC_B.Merge - (rtb_Sum_b * cosf(LBG_Arctan_FOC_B.Merge2)
    + rtb_ibeta * sinf(LBG_Arctan_FOC_B.Merge2));

  /* DiscreteIntegrator: '<S249>/Integrator' */
  if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE == 0) {
    /* DiscreteIntegrator: '<S249>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_DSTATE += 5.0E-5F * (real32_T)
      LBG_Arctan_FOC_DW.FOC_ELAPS_T * LBG_Arctan_FOC_DW.Integrator_PREV_U;
  }

  /* End of DiscreteIntegrator: '<S249>/Integrator' */

  /* Sum: '<S258>/Sum' incorporates:
   *  Gain: '<S254>/Proportional Gain'
   */
  rtb_Saturation = 0.485F * rtb_Sum2 + LBG_Arctan_FOC_DW.Integrator_DSTATE;

  /* Saturate: '<S256>/Saturation' */
  if (rtb_Saturation > 6.92820311F) {
    rtb_Saturation = 6.92820311F;
  } else if (rtb_Saturation < -6.92820311F) {
    rtb_Saturation = -6.92820311F;
  }

  /* End of Saturate: '<S256>/Saturation' */

  /* Sum: '<S7>/Sum3' incorporates:
   *  MATLAB Function: '<S7>/Park'
   */
  rtb_Sum3 = LBG_Arctan_FOC_B.Merge1 - (-rtb_Sum_b * sinf
    (LBG_Arctan_FOC_B.Merge2) + rtb_ibeta * cosf(LBG_Arctan_FOC_B.Merge2));

  /* DiscreteIntegrator: '<S297>/Integrator' */
  if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_e == 0) {
    /* DiscreteIntegrator: '<S297>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_DSTATE_c += 5.0E-5F * (real32_T)
      LBG_Arctan_FOC_DW.FOC_ELAPS_T * LBG_Arctan_FOC_DW.Integrator_PREV_U_c;
  }

  /* End of DiscreteIntegrator: '<S297>/Integrator' */

  /* Sum: '<S306>/Sum' incorporates:
   *  Gain: '<S302>/Proportional Gain'
   */
  rtb_Saturation_l = 0.485F * rtb_Sum3 + LBG_Arctan_FOC_DW.Integrator_DSTATE_c;

  /* Saturate: '<S304>/Saturation' */
  if (rtb_Saturation_l > 6.92820311F) {
    rtb_Saturation_l = 6.92820311F;
  } else if (rtb_Saturation_l < -6.92820311F) {
    rtb_Saturation_l = -6.92820311F;
  }

  /* End of Saturate: '<S304>/Saturation' */

  /* MATLAB Function: '<S7>/svpwm' incorporates:
   *  Constant: '<S7>/Constant'
   *  Constant: '<S7>/Constant1'
   */
  beta = atanf(rtb_Saturation_l / fabsf(rtb_Saturation));
  if (rtb_Saturation * rtb_Saturation + rtb_Saturation_l * rtb_Saturation_l >
      48.0F) {
    rtb_Tcmp3 = cosf(beta);
    rtb_Saturation = -6.92820311F * rtb_Tcmp3;
    rtb_Saturation_l = 6.92820311F * sinf(beta);
    if (rtb_Saturation > 0.0F) {
      rtb_Saturation = 6.92820311F * rtb_Tcmp3;
    }
  }

  rtb_Tcmp3 = sinf(LBG_Arctan_FOC_B.Merge2);
  rtb_Vbeta = cosf(LBG_Arctan_FOC_B.Merge2);
  beta = rtb_Saturation * rtb_Vbeta - rtb_Saturation_l * rtb_Tcmp3;
  rtb_Vbeta = rtb_Saturation * rtb_Tcmp3 + rtb_Saturation_l * rtb_Vbeta;
  sector = 0;
  rtb_Saturation = 0.0F;
  rtb_Saturation_l = 0.0F;
  rtb_Tcmp3 = 0.0F;
  if (rtb_Vbeta > 0.0F) {
    sector = 1;
  }

  if ((1.73205078F * beta - rtb_Vbeta) / 2.0F > 0.0F) {
    sector += 2;
  }

  if ((-1.73205078F * beta - rtb_Vbeta) / 2.0F > 0.0F) {
    sector += 4;
  }

  switch (sector) {
   case 1:
    T1 = (-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    T2 = (1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    break;

   case 2:
    T1 = (1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    T2 = -(1.73205078F * rtb_Vbeta * 8192.0F / 12.0F);
    break;

   case 3:
    T1 = -((-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    T2 = 1.73205078F * rtb_Vbeta * 8192.0F / 12.0F;
    break;

   case 4:
    T1 = -(1.73205078F * rtb_Vbeta * 8192.0F / 12.0F);
    T2 = (-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F;
    break;

   case 5:
    T1 = 1.73205078F * rtb_Vbeta * 8192.0F / 12.0F;
    T2 = -((1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    break;

   default:
    T1 = -((1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    T2 = -((-1.5F * beta + 0.866025388F * rtb_Vbeta) * 682.666687F);
    break;
  }

  ta = (8192.0F - (T1 + T2)) / 4.0F;
  T1 = T1 / 2.0F + ta;
  T2 = T2 / 2.0F + T1;
  ta = roundf(ta);
  T1 = roundf(T1);
  switch (sector) {
   case 1:
    rtb_Saturation = T1;
    rtb_Saturation_l = ta;
    rtb_Tcmp3 = roundf(T2);
    break;

   case 2:
    rtb_Saturation = ta;
    rtb_Saturation_l = roundf(T2);
    rtb_Tcmp3 = T1;
    break;

   case 3:
    rtb_Saturation = ta;
    rtb_Saturation_l = T1;
    rtb_Tcmp3 = roundf(T2);
    break;

   case 4:
    rtb_Saturation = roundf(T2);
    rtb_Saturation_l = T1;
    rtb_Tcmp3 = ta;
    break;

   case 5:
    rtb_Saturation = roundf(T2);
    rtb_Saturation_l = ta;
    rtb_Tcmp3 = T1;
    break;

   case 6:
    rtb_Saturation = T1;
    rtb_Saturation_l = roundf(T2);
    rtb_Tcmp3 = ta;
    break;
  }

  /* End of MATLAB Function: '<S7>/svpwm' */

  /* Product: '<S12>/Product2' incorporates:
   *  Product: '<S12>/Product8'
   */
  ta = rtb_ibeta * LBG_Arctan_FOC_DW.Delay_DSTATE_n;

  /* Sum: '<S12>/Add4' incorporates:
   *  Delay: '<S12>/Delay'
   *  Gain: '<S12>/Gain1'
   *  Gain: '<S12>/Gain2'
   *  Gain: '<S12>/Gain3'
   *  Gain: '<S12>/Gain4'
   *  Product: '<S12>/Product'
   *  Product: '<S12>/Product1'
   *  Product: '<S12>/Product2'
   *  Product: '<S12>/Product3'
   *  Sum: '<S12>/Add2'
   *  Sum: '<S12>/Add3'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_a = ((0.1F * rtb_Sum_b - ta * 5.0E-5F) *
    LBG_Arctan_FOC_ConstB.Add1 + LBG_Arctan_FOC_DW.Delay_DSTATE_a *
    LBG_Arctan_FOC_ConstB.Add) + (0.1F * beta - LBG_Arctan_FOC_DW.Delay_DSTATE_n
    * rtb_Vbeta * 5.0E-5F);

  /* Product: '<S12>/Product6' incorporates:
   *  Product: '<S12>/Product9'
   */
  T2 = rtb_Sum_b * LBG_Arctan_FOC_DW.Delay_DSTATE_n;

  /* Sum: '<S12>/Add9' incorporates:
   *  Delay: '<S12>/Delay1'
   *  Gain: '<S12>/Gain6'
   *  Gain: '<S12>/Gain7'
   *  Gain: '<S12>/Gain8'
   *  Gain: '<S12>/Gain9'
   *  Product: '<S12>/Product4'
   *  Product: '<S12>/Product5'
   *  Product: '<S12>/Product6'
   *  Product: '<S12>/Product7'
   *  Sum: '<S12>/Add7'
   *  Sum: '<S12>/Add8'
   */
  LBG_Arctan_FOC_DW.Delay1_DSTATE = ((T2 * 5.0E-5F + 0.1F * rtb_ibeta) *
    LBG_Arctan_FOC_ConstB.Add6 + LBG_Arctan_FOC_DW.Delay1_DSTATE *
    LBG_Arctan_FOC_ConstB.Add5) + (LBG_Arctan_FOC_DW.Delay_DSTATE_n * beta *
    5.0E-5F + 0.1F * rtb_Vbeta);

  /* Sum: '<S23>/Add1' incorporates:
   *  Constant: '<S23>/One'
   *  Product: '<S23>/Product1'
   *  UnitDelay: '<S23>/Unit Delay'
   */
  LBG_Arctan_FOC_DW.UnitDelay_DSTATE = 0.98F *
    LBG_Arctan_FOC_DW.UnitDelay_DSTATE + LBG_Arctan_FOC_ConstB.Product;

  /* Outputs for Atomic SubSystem: '<S13>/atan2' */
  /* Trigonometry: '<S17>/Atan2' incorporates:
   *  Delay: '<S12>/Delay'
   *  Delay: '<S12>/Delay1'
   *  Gain: '<S12>/Gain10'
   *  Gain: '<S12>/Gain11'
   *  Gain: '<S12>/Gain12'
   *  Gain: '<S12>/Gain13'
   *  Sum: '<S12>/Add10'
   *  Sum: '<S12>/Add11'
   */
  ta = rt_atan2f_snf((LBG_Arctan_FOC_DW.Delay_DSTATE_a - 0.194F * rtb_Sum_b) +
                     ta * 9.7E-5F, (LBG_Arctan_FOC_DW.Delay1_DSTATE - 0.194F *
    rtb_ibeta) - T2 * 9.7E-5F);

  /* Outputs for Enabled SubSystem: '<S17>/If Action Subsystem' incorporates:
   *  EnablePort: '<S28>/Enable'
   */
  /* Merge: '<S17>/Merge' incorporates:
   *  SignalConversion generated from: '<S28>/In1'
   */
  T2 = ta;

  /* End of Outputs for SubSystem: '<S17>/If Action Subsystem' */

  /* Outputs for Enabled SubSystem: '<S17>/per Uint' */
  /* RelationalOperator: '<S27>/Compare' incorporates:
   *  Constant: '<S17>/Constant'
   *  Constant: '<S27>/Constant'
   */
  LBG_Arctan_FOC_perUint(false, ta, &T2);

  /* End of Outputs for SubSystem: '<S17>/per Uint' */
  /* End of Outputs for SubSystem: '<S13>/atan2' */

  /* Delay: '<S30>/Delay2' */
  ta = LBG_Arctan_FOC_DW.Delay2_DSTATE;

  /* Saturate: '<S11>/Saturation' incorporates:
   *  Delay: '<S11>/Delay'
   */
  if (OB_LGB_SPD > 11000.0F) {
    T2 = 11000.0F;
  } else if (OB_LGB_SPD < -11000.0F) {
    T2 = -11000.0F;
  } else {
    T2 = OB_LGB_SPD;
  }

  /* End of Saturate: '<S11>/Saturation' */

  /* Delay: '<S30>/Delay3' */
  T1 = LBG_Arctan_FOC_DW.Delay3_DSTATE;

  /* Sum: '<S30>/Add10' incorporates:
   *  Constant: '<S30>/Constant2'
   *  Delay: '<S30>/Delay'
   *  Delay: '<S30>/Delay2'
   *  Delay: '<S30>/Delay3'
   *  Gain: '<S30>/Gain'
   *  Product: '<S30>/Product1'
   *  Product: '<S30>/Product8'
   *  Sum: '<S30>/Add1'
   */
  LBG_Arctan_FOC_DW.Delay2_DSTATE = (LBG_Arctan_FOC_DW.Delay2_DSTATE - 5.0E-5F *
    T2 * LBG_Arctan_FOC_DW.Delay3_DSTATE) + (LBG_Arctan_FOC_DW.Delay_DSTATE_p -
    rtb_Sum_b) * 0.58685F;

  /* Sum: '<S30>/Add3' incorporates:
   *  Constant: '<S30>/Constant3'
   *  Delay: '<S30>/Delay1'
   *  Delay: '<S30>/Delay3'
   *  Gain: '<S30>/Gain1'
   *  Product: '<S30>/Product2'
   *  Product: '<S30>/Product3'
   *  Sum: '<S30>/Add2'
   */
  LBG_Arctan_FOC_DW.Delay3_DSTATE = (5.0E-5F * T2 * ta +
    LBG_Arctan_FOC_DW.Delay3_DSTATE) + (LBG_Arctan_FOC_DW.Delay1_DSTATE_e -
    rtb_ibeta) * 0.58685F;

  /* Sum: '<S30>/Add4' incorporates:
   *  Constant: '<S30>/Constant10'
   *  Constant: '<S30>/Constant9'
   *  Delay: '<S30>/Delay'
   *  Product: '<S30>/Product'
   *  Product: '<S30>/Product10'
   *  Product: '<S30>/Product11'
   *  Product: '<S30>/Product12'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_p = ((LBG_Arctan_FOC_DW.Delay_DSTATE_p *
    LBG_Arctan_FOC_ConstB.Add_p - 0.515463889F * ta) + 0.515463889F * beta) -
    (-rtb_Sum_b);

  /* Sum: '<S30>/Add6' incorporates:
   *  Constant: '<S30>/Constant13'
   *  Constant: '<S30>/Constant6'
   *  Delay: '<S30>/Delay1'
   *  Product: '<S30>/Product4'
   *  Product: '<S30>/Product5'
   *  Product: '<S30>/Product6'
   *  Product: '<S30>/Product7'
   */
  LBG_Arctan_FOC_DW.Delay1_DSTATE_e = ((LBG_Arctan_FOC_DW.Delay1_DSTATE_e *
    LBG_Arctan_FOC_ConstB.Add5_b - 0.515463889F * T1) + 0.515463889F * rtb_Vbeta)
    - (-rtb_ibeta);

  /* Outputs for Atomic SubSystem: '<S31>/atan2' */
  /* Trigonometry: '<S41>/Atan2' incorporates:
   *  Delay: '<S30>/Delay2'
   *  Delay: '<S30>/Delay3'
   */
  ta = rt_atan2f_snf(LBG_Arctan_FOC_DW.Delay2_DSTATE,
                     LBG_Arctan_FOC_DW.Delay3_DSTATE);

  /* Outputs for Enabled SubSystem: '<S41>/If Action Subsystem' incorporates:
   *  EnablePort: '<S108>/Enable'
   */
  /* Merge: '<S41>/Merge' incorporates:
   *  SignalConversion generated from: '<S108>/In1'
   */
  LBG_Arctan_FOC_B.Merge_n = ta;

  /* End of Outputs for SubSystem: '<S41>/If Action Subsystem' */

  /* Outputs for Enabled SubSystem: '<S41>/per Uint' */
  /* RelationalOperator: '<S107>/Compare' incorporates:
   *  Constant: '<S107>/Constant'
   *  Constant: '<S41>/Constant'
   */
  LBG_Arctan_FOC_perUint(false, ta, &LBG_Arctan_FOC_B.Merge_n);

  /* End of Outputs for SubSystem: '<S41>/per Uint' */
  /* End of Outputs for SubSystem: '<S31>/atan2' */

  /* Sum: '<S115>/sum_beta' incorporates:
   *  Delay: '<S30>/Delay2'
   *  Delay: '<S30>/Delay3'
   *  MATLAB Function: '<S31>/MATLAB cos'
   *  MATLAB Function: '<S31>/MATLAB sin'
   *  Product: '<S31>/Product4'
   *  Product: '<S31>/Product5'
   *  Sum: '<S31>/Add8'
   *  UnitDelay: '<S40>/Unit Delay'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_n = (0.0F - LBG_Arctan_FOC_DW.Delay2_DSTATE *
    cosf(LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m)) -
    LBG_Arctan_FOC_DW.Delay3_DSTATE * sinf(LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m);

  /* MATLAB Function: '<S31>/MATLAB Function' */
  if (arg_Target_Speed >= 0.0F) {
    ta = 0.0F;
  } else {
    ta = -3.14159274F;
  }

  /* Outputs for Atomic SubSystem: '<S31>/atan2' */
  /* Math: '<S31>/Math Function' incorporates:
   *  AlgorithmDescriptorDelegate generated from: '<S41>/a16'
   *  Constant: '<S31>/Constant'
   *  Gain: '<S31>/Gain'
   *  MATLAB Function: '<S31>/MATLAB Function'
   *  Sum: '<S31>/Add'
   */
  LGB_theta = rt_modf_snf(-LBG_Arctan_FOC_B.Merge_n + ta, 6.28318548F);

  /* End of Outputs for SubSystem: '<S31>/atan2' */

  /* Gain: '<S39>/PositionToCount' */
  ta = truncf(6.83563648E+8F * LGB_theta);
  if (rtIsNaNF(ta)) {
    ta = 0.0F;
  } else {
    ta = fmodf(ta, 4.2949673E+9F);
  }

  /* Sum: '<S44>/Add1' incorporates:
   *  Constant: '<S44>/Filter_Constant'
   *  Constant: '<S44>/One'
   *  DataTypeConversion: '<S101>/DTC'
   *  Delay: '<S39>/Delay'
   *  Gain: '<S31>/Gain1'
   *  Gain: '<S39>/PositionToCount'
   *  Gain: '<S39>/SpeedGain'
   *  Product: '<S44>/Product'
   *  Product: '<S44>/Product1'
   *  Sum: '<S39>/SpeedCount'
   *  UnitDelay: '<S44>/Unit Delay'
   */
  LGB_SPD = (real32_T)((int32_T)(uint32_T)ta - (int32_T)
                       LBG_Arctan_FOC_DW.Delay_DSTATE_m[LBG_Arctan_FOC_DW.CircBufIdx])
    * 6.98491931E-5F * 0.142857149F * 0.02F + 0.98F * LGB_SPD;

  /* Sum: '<S47>/Add1' incorporates:
   *  Constant: '<S47>/Filter_Constant'
   *  Constant: '<S47>/One'
   *  Gain: '<S31>/f_2_we'
   *  Gain: '<S31>/n_2_f'
   *  Product: '<S47>/Product'
   *  Product: '<S47>/Product1'
   *  UnitDelay: '<S47>/Unit Delay'
   */
  OB_LGB_SPD = 0.116666667F * LGB_SPD * 6.28318548F * 0.02F + 0.98F * OB_LGB_SPD;

  /* DiscreteIntegrator: '<S82>/Integrator' */
  if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_d == 0) {
    /* DiscreteIntegrator: '<S82>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_DSTATE_f += 5.0E-5F * (real32_T)
      LBG_Arctan_FOC_DW.FOC_ELAPS_T * LBG_Arctan_FOC_DW.Integrator_PREV_U_d;
  }

  /* End of DiscreteIntegrator: '<S82>/Integrator' */

  /* Sum: '<S92>/Sum' incorporates:
   *  Constant: '<S31>/Constant23'
   *  Product: '<S87>/PProd Out'
   */
  rtb_Sum_f = LBG_Arctan_FOC_DW.Delay_DSTATE_n * 100.0F +
    LBG_Arctan_FOC_DW.Integrator_DSTATE_f;

  /* Switch: '<S75>/Switch' incorporates:
   *  Constant: '<S31>/Constant25'
   *  Constant: '<S31>/Constant26'
   *  RelationalOperator: '<S75>/u_GTE_up'
   *  RelationalOperator: '<S75>/u_GT_lo'
   *  Switch: '<S75>/Switch1'
   */
  if (rtb_Sum_f >= 6283.18555F) {
    T1 = 6283.18555F;
  } else if (rtb_Sum_f > -6283.18555F) {
    /* Switch: '<S75>/Switch1' */
    T1 = rtb_Sum_f;
  } else {
    T1 = -6283.18555F;
  }

  /* Sum: '<S75>/Diff' incorporates:
   *  Switch: '<S75>/Switch'
   */
  T2 = rtb_Sum_f - T1;

  /* Sum: '<S115>/sum_beta' incorporates:
   *  Constant: '<S31>/Constant24'
   *  Product: '<S79>/IProd Out'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_n *= 500000.0F;

  /* Switch: '<S72>/Switch1' incorporates:
   *  Constant: '<S72>/Clamping_zero'
   *  Constant: '<S72>/Constant'
   *  Constant: '<S72>/Constant2'
   *  RelationalOperator: '<S72>/fix for DT propagation issue'
   */
  if (T2 > 0.0F) {
    rtPrevAction = 1;
  } else {
    rtPrevAction = -1;
  }

  /* Switch: '<S72>/Switch2' incorporates:
   *  Constant: '<S72>/Clamping_zero'
   *  Constant: '<S72>/Constant3'
   *  Constant: '<S72>/Constant4'
   *  RelationalOperator: '<S72>/fix for DT propagation issue1'
   */
  if (LBG_Arctan_FOC_DW.Delay_DSTATE_n > 0.0F) {
    tmp_0 = 1;
  } else {
    tmp_0 = -1;
  }

  /* Switch: '<S72>/Switch' incorporates:
   *  Constant: '<S72>/Clamping_zero'
   *  Logic: '<S72>/AND3'
   *  RelationalOperator: '<S72>/Equal1'
   *  RelationalOperator: '<S72>/Relational Operator'
   *  Switch: '<S72>/Switch1'
   *  Switch: '<S72>/Switch2'
   */
  if ((T2 != 0.0F) && (rtPrevAction == tmp_0)) {
    /* Update for DiscreteIntegrator: '<S82>/Integrator' incorporates:
     *  Constant: '<S72>/Constant1'
     */
    LBG_Arctan_FOC_DW.Integrator_PREV_U_d = 0.0F;
  } else {
    /* Update for DiscreteIntegrator: '<S82>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_PREV_U_d = LBG_Arctan_FOC_DW.Delay_DSTATE_n;
  }

  /* End of Switch: '<S72>/Switch' */

  /* Switch: '<S90>/Switch2' incorporates:
   *  Constant: '<S31>/Constant25'
   *  Constant: '<S31>/Constant26'
   *  RelationalOperator: '<S90>/LowerRelop1'
   *  RelationalOperator: '<S90>/UpperRelop'
   *  Switch: '<S90>/Switch'
   */
  if (rtb_Sum_f > 6283.18555F) {
    rtb_Sum_f = 6283.18555F;
  } else if (rtb_Sum_f < -6283.18555F) {
    /* Switch: '<S90>/Switch' incorporates:
     *  Constant: '<S31>/Constant26'
     */
    rtb_Sum_f = -6283.18555F;
  }

  /* Sum: '<S40>/Sum1' incorporates:
   *  Gain: '<S40>/Ts'
   *  Switch: '<S90>/Switch2'
   *  UnitDelay: '<S40>/Unit Delay'
   */
  LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m += 0.0001F * rtb_Sum_f;

  /* If: '<S102>/If1' */
  if (LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m > 6.28318548F) {
    /* Outputs for IfAction SubSystem: '<S102>/If Action Subsystem2' incorporates:
     *  ActionPort: '<S104>/Action Port'
     */
    /* Sum: '<S40>/Sum1' incorporates:
     *  Constant: '<S104>/2pi'
     *  Sum: '<S104>/Subtract1'
     */
    LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m -= 6.28318548F;

    /* End of Outputs for SubSystem: '<S102>/If Action Subsystem2' */
  } else if (LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m < 0.0F) {
    /* Outputs for IfAction SubSystem: '<S102>/If Action Subsystem3' incorporates:
     *  ActionPort: '<S105>/Action Port'
     */
    /* Sum: '<S40>/Sum1' incorporates:
     *  Constant: '<S105>/Angle_offset'
     *  Sum: '<S105>/Subtract1'
     */
    LBG_Arctan_FOC_DW.UnitDelay_DSTATE_m += 6.28318548F;

    /* End of Outputs for SubSystem: '<S102>/If Action Subsystem3' */
  }

  /* End of If: '<S102>/If1' */

  /* Gain: '<S323>/convert_pu' */
  T2 = 0.159154937F * LBG_Arctan_FOC_B.Merge2;

  /* If: '<S323>/If' incorporates:
   *  Constant: '<S324>/Constant'
   *  RelationalOperator: '<S324>/Compare'
   */
  if (T2 < 0.0F) {
    /* Outputs for IfAction SubSystem: '<S323>/If Action Subsystem' incorporates:
     *  ActionPort: '<S325>/Action Port'
     */
    /* DataTypeConversion: '<S325>/Convert_uint16' */
    T1 = floorf(T2);
    if (rtIsInfF(T1)) {
      T1 = 0.0F;
    } else {
      T1 = fmodf(T1, 65536.0F);
    }

    /* Sum: '<S325>/Sum' incorporates:
     *  DataTypeConversion: '<S325>/Convert_back'
     *  DataTypeConversion: '<S325>/Convert_uint16'
     */
    T2 -= (real32_T)(T1 < 0.0F ? (int32_T)(int16_T)-(int16_T)(uint16_T)-T1 :
                     (int32_T)(int16_T)(uint16_T)T1);

    /* End of Outputs for SubSystem: '<S323>/If Action Subsystem' */
  } else {
    /* Outputs for IfAction SubSystem: '<S323>/If Action Subsystem1' incorporates:
     *  ActionPort: '<S326>/Action Port'
     */
    /* DataTypeConversion: '<S326>/Convert_uint16' */
    T1 = truncf(T2);
    if (rtIsNaNF(T1) || rtIsInfF(T1)) {
      T1 = 0.0F;
    } else {
      T1 = fmodf(T1, 65536.0F);
    }

    /* Sum: '<S326>/Sum' incorporates:
     *  DataTypeConversion: '<S326>/Convert_back'
     *  DataTypeConversion: '<S326>/Convert_uint16'
     */
    T2 -= (real32_T)(int16_T)(uint16_T)T1;

    /* End of Outputs for SubSystem: '<S323>/If Action Subsystem1' */
  }

  /* End of If: '<S323>/If' */

  /* Gain: '<S119>/indexing' */
  T2 *= 800.0F;

  /* DataTypeConversion: '<S119>/Get_Integer' */
  T1 = truncf(T2);
  if (rtIsNaNF(T1) || rtIsInfF(T1)) {
    T1 = 0.0F;
  } else {
    T1 = fmodf(T1, 65536.0F);
  }

  rtb_Get_Integer = (uint16_T)(T1 < 0.0F ? (int32_T)(uint16_T)-(int16_T)
    (uint16_T)-T1 : (int32_T)(uint16_T)T1);

  /* End of DataTypeConversion: '<S119>/Get_Integer' */

  /* Sum: '<S119>/Sum2' incorporates:
   *  DataTypeConversion: '<S119>/Data Type Conversion1'
   */
  T1 = T2 - (real32_T)rtb_Get_Integer;

  /* Selector: '<S119>/Lookup' incorporates:
   *  Constant: '<S119>/sine_table_values'
   *  Sum: '<S119>/Sum'
   */
  T2 = rtCP_sine_table_values_Value[rtb_Get_Integer];

  /* Sum: '<S322>/Sum4' incorporates:
   *  Constant: '<S119>/offset'
   *  Constant: '<S119>/sine_table_values'
   *  Product: '<S322>/Product'
   *  Selector: '<S119>/Lookup'
   *  Sum: '<S119>/Sum'
   *  Sum: '<S322>/Sum3'
   */
  rtb_Sum_f = (rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 1U)] -
               T2) * T1 + T2;

  /* Selector: '<S119>/Lookup' incorporates:
   *  Constant: '<S119>/offset'
   *  Constant: '<S119>/sine_table_values'
   *  Sum: '<S119>/Sum'
   *  Sum: '<S322>/Sum5'
   */
  T2 = rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 200U)];

  /* Sum: '<S322>/Sum6' incorporates:
   *  Constant: '<S119>/offset'
   *  Constant: '<S119>/sine_table_values'
   *  Product: '<S322>/Product1'
   *  Selector: '<S119>/Lookup'
   *  Sum: '<S119>/Sum'
   *  Sum: '<S322>/Sum5'
   */
  rtb_Sum6 = (rtCP_sine_table_values_Value[(int32_T)(rtb_Get_Integer + 201U)] -
              T2) * T1 + T2;

  /* Outputs for Atomic SubSystem: '<S7>/Park Transform' */
  /* Sum: '<S7>/Sum' incorporates:
   *  Product: '<S118>/acos'
   *  Product: '<S118>/bsin'
   *  Sum: '<S118>/sum_Ds'
   */
  T1 = LBG_Arctan_FOC_B.Merge - (rtb_Sum_b * rtb_Sum6 + rtb_ibeta * rtb_Sum_f);

  /* End of Outputs for SubSystem: '<S7>/Park Transform' */

  /* DiscreteIntegrator: '<S153>/Integrator' */
  if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_g == 0) {
    /* DiscreteIntegrator: '<S153>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_DSTATE_p += 5.0E-5F * (real32_T)
      LBG_Arctan_FOC_DW.FOC_ELAPS_T * LBG_Arctan_FOC_DW.Integrator_PREV_U_c2;
  }

  /* End of DiscreteIntegrator: '<S153>/Integrator' */

  /* Sum: '<S162>/Sum' incorporates:
   *  Gain: '<S158>/Proportional Gain'
   */
  rtb_Saturation_a = 0.485F * T1 + LBG_Arctan_FOC_DW.Integrator_DSTATE_p;

  /* Saturate: '<S160>/Saturation' */
  if (rtb_Saturation_a > 6.92820311F) {
    rtb_Saturation_a = 6.92820311F;
  } else if (rtb_Saturation_a < -6.92820311F) {
    rtb_Saturation_a = -6.92820311F;
  }

  /* End of Saturate: '<S160>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S7>/Park Transform' */
  /* Sum: '<S7>/Sum1' incorporates:
   *  Product: '<S118>/asin'
   *  Product: '<S118>/bcos'
   *  Sum: '<S118>/sum_Qs'
   */
  T2 = LBG_Arctan_FOC_B.Merge1 - (rtb_ibeta * rtb_Sum6 - rtb_Sum_b * rtb_Sum_f);

  /* End of Outputs for SubSystem: '<S7>/Park Transform' */

  /* DiscreteIntegrator: '<S201>/Integrator' */
  if (LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m == 0) {
    /* DiscreteIntegrator: '<S201>/Integrator' */
    LBG_Arctan_FOC_DW.Integrator_DSTATE_m += 5.0E-5F * (real32_T)
      LBG_Arctan_FOC_DW.FOC_ELAPS_T * LBG_Arctan_FOC_DW.Integrator_PREV_U_b;
  }

  /* End of DiscreteIntegrator: '<S201>/Integrator' */

  /* Sum: '<S210>/Sum' incorporates:
   *  Gain: '<S206>/Proportional Gain'
   */
  rtb_Saturation_h = 0.485F * T2 + LBG_Arctan_FOC_DW.Integrator_DSTATE_m;

  /* Saturate: '<S208>/Saturation' */
  if (rtb_Saturation_h > 6.92820311F) {
    rtb_Saturation_h = 6.92820311F;
  } else if (rtb_Saturation_h < -6.92820311F) {
    rtb_Saturation_h = -6.92820311F;
  }

  /* End of Saturate: '<S208>/Saturation' */

  /* Outputs for Atomic SubSystem: '<S7>/Inverse Park Transform' */
  /* AlgorithmDescriptorDelegate generated from: '<S115>/a16' incorporates:
   *  Product: '<S115>/dcos'
   *  Product: '<S115>/dsin'
   *  Product: '<S115>/qcos'
   *  Product: '<S115>/qsin'
   *  Sum: '<S115>/sum_alpha'
   *  Sum: '<S115>/sum_beta'
   */
  rtb_algDD_o1_m = rtb_Saturation_a * rtb_Sum6 - rtb_Saturation_h * rtb_Sum_f;
  rtb_Sum_f = rtb_Saturation_h * rtb_Sum6 + rtb_Saturation_a * rtb_Sum_f;

  /* End of Outputs for SubSystem: '<S7>/Inverse Park Transform' */
  /* Sum: '<S7>/Sum6' incorporates:
   *  Constant: '<S7>/Constant3'
   *  Constant: '<S7>/Constant4'
   *  Gain: '<S7>/Gain1'
   *  Gain: '<S7>/Gain2'
   *  Sum: '<S7>/Sum5'
   */
  arg_Vabc_PU[0] = -(0.000244140625F * rtb_Saturation - 0.5F) + 0.5F;
  arg_Vabc_PU[1] = -(0.000244140625F * rtb_Saturation_l - 0.5F) + 0.5F;
  arg_Vabc_PU[2] = -(0.000244140625F * rtb_Tcmp3 - 0.5F) + 0.5F;

  /* Update for Sum: '<S115>/sum_beta' incorporates:
   *  Delay: '<S10>/Delay'
   *  UnitDelay: '<S23>/Unit Delay'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_n = LBG_Arctan_FOC_DW.UnitDelay_DSTATE;

  /* Update for SwitchCase: '<S9>/Switch Case' */
  switch (LBG_Arctan_FOC_DW.SwitchCase_ActiveSubsystem) {
   case 0:
   case 2:
    break;

   case 1:
    /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem1' incorporates:
     *  ActionPort: '<S330>/Action Port'
     */
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_PREV =
      LBG_Arctan_FOC_DW.FOC_PREV_T;
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem1_RESE = false;

    /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem1' */
    break;

   case 3:
    /* Update for IfAction SubSystem: '<S9>/Switch Case Action Subsystem3' incorporates:
     *  ActionPort: '<S332>/Action Port'
     */
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_PREV =
      LBG_Arctan_FOC_DW.FOC_PREV_T;
    LBG_Arctan_FOC_DW.SwitchCaseActionSubsystem3_RESE = false;

    /* End of Update for SubSystem: '<S9>/Switch Case Action Subsystem3' */
    break;
  }

  /* Update for DiscreteIntegrator: '<S249>/Integrator' incorporates:
   *  Gain: '<S246>/Integral Gain'
   */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE = 0U;
  LBG_Arctan_FOC_DW.Integrator_PREV_U = 970.0F * rtb_Sum2;

  /* Update for DiscreteIntegrator: '<S297>/Integrator' incorporates:
   *  Gain: '<S294>/Integral Gain'
   */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_e = 0U;
  LBG_Arctan_FOC_DW.Integrator_PREV_U_c = 970.0F * rtb_Sum3;

  /* Update for Delay: '<S39>/Delay' incorporates:
   *  Gain: '<S39>/PositionToCount'
   */
  LBG_Arctan_FOC_DW.Delay_DSTATE_m[LBG_Arctan_FOC_DW.CircBufIdx] = (uint32_T)ta;
  if (LBG_Arctan_FOC_DW.CircBufIdx < 3U) {
    LBG_Arctan_FOC_DW.CircBufIdx++;
  } else {
    LBG_Arctan_FOC_DW.CircBufIdx = 0U;
  }

  /* End of Update for Delay: '<S39>/Delay' */

  /* Update for DiscreteIntegrator: '<S82>/Integrator' */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_d = 0U;

  /* Update for DiscreteIntegrator: '<S153>/Integrator' incorporates:
   *  Gain: '<S150>/Integral Gain'
   */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_g = 0U;
  LBG_Arctan_FOC_DW.Integrator_PREV_U_c2 = 970.0F * T1;

  /* Update for DiscreteIntegrator: '<S201>/Integrator' incorporates:
   *  Gain: '<S198>/Integral Gain'
   */
  LBG_Arctan_FOC_DW.Integrator_SYSTEM_ENABLE_m = 0U;
  LBG_Arctan_FOC_DW.Integrator_PREV_U_b = 970.0F * T2;

  /* End of Outputs for S-Function (fcgen): '<S1>/Function-Call Generator4' */
}

/* Model initialize function */
void LBG_Arctan_FOC_initialize(const char_T **rt_errorStatus, const
  rtTimingBridge *timingBridge, int_T mdlref_TID0, int_T mdlref_TID1, int_T
  mdlref_TID2)
{
  RT_MODEL_LBG_Arctan_FOC_T *const LBG_Arctan_FOC_M =
    &(LBG_Arctan_FOC_MdlrefDW.rtm);

  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* setup the global timing engine */
  LBG_Arctan_FOC_GlobalTID[0] = mdlref_TID0;
  LBG_Arctan_FOC_GlobalTID[1] = mdlref_TID1;
  LBG_Arctan_FOC_GlobalTID[2] = mdlref_TID2;
  LBG_Arctan_FOC_TimingBrdg = timingBridge;

  /* initialize error status */
  rtmSetErrorStatusPointer(LBG_Arctan_FOC_M, rt_errorStatus);
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
